package com.ahj.location;

import android.app.Activity;
import android.content.Intent;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class ChoiceLocationPlugin implements MethodChannel.MethodCallHandler {
    public static final String CHANNEL = "com.qingning.qn/ChoiceLocationUtils";
    static MethodChannel channe;
    private Activity activity;

    public ChoiceLocationPlugin(Activity activity) {
        this.activity = activity;
    }
    public static MethodChannel.Result mResult;

    public static void registerWith(FlutterEngine flutterEngine, Activity activity12) {
        channe = new MethodChannel(flutterEngine.getDartExecutor(), CHANNEL);
        ChoiceLocationPlugin plugin = new ChoiceLocationPlugin(activity12);
        channe.setMethodCallHandler(plugin);

    }


    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        try {
            mResult=result;
            if (methodCall.method.equals("choice_location")) {
                String address = methodCall.argument("address");
                Intent intent = new Intent(activity, LocationActivity.class);
                intent.putExtra("address", address);
                activity.startActivity(intent);
            } else {
                result.notImplemented();
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.success(e.getMessage());
        }
    }

}
